﻿using Microsoft.AspNetCore.Builder;
using System;
using System.Linq;

namespace Xlit.Example.Business.Mapper
{
    using Mapper = AutoMapper.Mapper;
    using MapperConfigurationExpression = AutoMapper.Configuration.MapperConfigurationExpression;

    public static class AutoMapperExtensions
    {
        public static void UseAutoMapper(this IApplicationBuilder builder)
        {
            var assembly = AppDomain.CurrentDomain
                .GetAssemblies()
                .Where(d => d.FullName.StartsWith("Xlit"));
            var config = new MapperConfigurationExpression();
            config.AddProfiles(assembly);
            Mapper.Initialize(config);
        }
    }
}
